function MenuButton(menuId, selector) {
	selector = selector == undefined ? '#toolbarDiv' : selector;
	
	var TARGET_A = '<a></a>';
	
	$.getJSON(__CREATEMENUBUTTON,{menuId: menuId},function(data){
		for(var d in data) {
			var tb = data[d];
			$(selector).append($(TARGET_A).linkbutton({
											  id: 'buttonid_'+tb.buttonId,
								              text: tb.buttonName,
								              plain: true,
								              iconCls: tb.icon
								          })
								          .bind('click', eval(tb.func)));
		}
	});
}

function ViewportLayout () {}
ViewportLayout.setLayout = function(viewLayout) {
	//自动适应大小
	viewLayout.layout('panel','center').panel({
		onResize : function(w,h) {
			viewLayout.layout('panel','center').datagrid('resize',{height:h});
		}
	});
};


/**
 * 定义包  Gzepro.utils
 */
S4J = {};
S4J.utils = {};

/**
 * 重置表格大小
 */
S4J.utils.gridResize = function() {
	
};

/**
 * datagrid分页
 */
S4J.utils.pagination = function() {
	return {
        pageSize: 10,//每页显示的记录条数，默认为10
        beforePageText: '第',//页数文本框前显示的汉字
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 页,共 {total} 条记录'
    };
};

S4J.utils.openWindow = function(title,moduleNo,params,divid,width,height,modal) {
		width = width ? width : document.body.offsetWidth;
		height = height ? height : document.body.offsetHeight;
		modal = modal || true;
		
		if(params) {
			var paramstr = '';
			for(var p in params) {
				paramstr += p + '=' + params[p] + '&';
			}
			paramstr = paramstr.indexOf('&') ? paramstr.substring(0,paramstr.length-1) : params;
			paramstr = '&'+ paramstr;
		} else {
			paramstr = '';
		}
		
		var winDiv = '<div id='+(divid || 'winDiv')+'></div>';
		$('#document').append($(winDiv).window({
			modal : modal,
			title : title,
			height : height,
			width : width,
			closable : false,
			collapsible: false,
			minimizable: false,
			maximizable: false,
			draggable: false,
			resizable: false,
			inline: false,
			border: false,
			content: '<iframe scrolling="no" frameborder="0" width="100%" height="100%" src="'
		                	  + __SHOWMAINVIEW
		                	  + '_mduno=' + moduleNo
		                	  + paramstr
		                	  + '"></iframe>' 
		}));
		
		return '#'+(divid || 'winDiv');
};

S4J.utils.showMessage = function(msg,than,title) {
	than = than || window;
	than.$.messager.show({
		msg:msg,  	
		timeout:5000,  	
		showType:'slide'
	});
};

var snsDialog;
S4J.utils.showSnsGridDialog = function(cfg) {
	var winDiv = '<div id=snsWinDiv>' +
		'<div>' + 
			'<label class=form_label_cls>请输入(回车查询)：</label>' + 
			'<input class=form_input_cls type=text id=sns_search onkeydown=doSnsQuery(\''+cfg.queryField+'\') />' + 
		'</div>' + 
		'<div id=snsPanelDiv style="heigth:200px;"></div>' + 
		'</div>';
	$('#document').append($(winDiv).window({
		title: '请双击选择',
		height : cfg.height || 400,
		width : cfg.width || 600,
		modal : true,
		maximizable: false,
		collapsible: false, 
		minimizable: false,
		onClose: function() {
			$('#snsWinDiv').window('destroy');
		}
	}));
	
	$('#snsPanelDiv').datagrid({
		url:cfg.url,
		columns:[cfg.columns],
		pagination: true,
	    pagePosition: 'bottom',
	    onDblClickRow: function(r,data) {
	    	$('#snsWinDiv').window('destroy');
	    	cfg.dbcFunc(data);
	    },
	    pagination: S4J.utils.pagination()
	}); 
	
// snsDialog = new JsEntityGrid(gridid,'#snsPanelDiv');
// snsDialog.initGrid(function() {
//		$('#snsWinDiv').window('options').onResize = function(w,h) {
//			snsDialog._datagrid.datagrid('resize',{height:h-60,width:w-15});
//		};
//		$('#snsWinDiv').window('resize',{height:height || 400,width:width || 600});
//		
//		//单选
//		snsDialog._datagrid.datagrid('options').singleSelect = true;
//		
//		snsDialog._datagrid.datagrid('options').onDblClickRow = function(r,data) {
//			$('#snsWinDiv').window('destroy');
//			dbcFunc(data);
//		};
//	});
};

//不能计算返回-1
S4J.utils.ages = function(str) {
	var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
	if (r == null)
		return -1;
	var d = new Date(r[1], r[3] - 1, r[4]);
	if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3]
			&& d.getDate() == r[4]) {
		var Y = new Date().getFullYear();
		return Y - r[1];
	}
	return -1;
};